import { createLogger, format, transports } from "winston";
import "winston-daily-rotate-file";
import path from "path";
import config from "config";

const myConfig = config.util.loadFileConfigs(path.join(__dirname, "..", "config"));
const logPath = myConfig.Log.courierLogPath;
const indexOfExt = logPath.lastIndexOf(path.extname(logPath));
const filename = `${logPath.slice(0, indexOfExt)}-%DATE%${logPath.slice(indexOfExt)}`;
const transport = new (transports.DailyRotateFile)({
    filename,
    datePattern: "YYYYMMDD",
    zippedArchive: true,
    maxSize: "15m",
    maxFiles: "14d",
}); 
const logger = createLogger({
    level: "info",
    format: format.combine(
        format.timestamp(),
        format.errors({ stack: true }),
        format.label({ label: "courier" }),
        format.printf(info => `${info.timestamp} ${info.label} ${info.level} "${info.message}" ${info.stack ? `stack:{ ${info.stack} }` : ""}`),
    ),
    transports: [
        transport,
    ],
});

export default logger;

